<?php
$item_name = strlen($dcommittee['Committee']['item_name'])>2 ? $dcommittee['Committee']['item_name'] : 'Project';
?>
<div class="items index">
    <?php if(isset($permission['Item']['Create']) && $permission['Item']['Create']): ?>
    <p class='contentmenu'>[ <?php echo $html->link(sprintf(__("Add new %s",true),ucwords($item_name)),array('committee'=>$dcommittee['Committee']['short_name'],'action'=>'add')); ?> ]</p>
    <?php endif; ?>
    
    <h2><?php echo ucwords($item_name);?></h2>
 
    <?php echo $this->element('searchbox',array('from'=>$this->params['controller'].'/'.$this->params['action']));?>
    <table cellpadding="0" cellspacing="0">
    <tr>
        
        <th width="3%"><?php __('No')?></th>
        <th width="50%"><?php echo $paginator->sort('name',null,array('url'=>array('committee'=>$dcommittee['Committee']['short_name'])));?></th>
        <th><?php echo $paginator->sort('short_name',null,array('url'=>array('committee'=>$dcommittee['Committee']['short_name'])));?></th>
        <th width="10%"><?php __('Start date');?></th>
        <th width="10%"><?php __('End date');?></th>
        <?php if ($auth_user['User']['superuser'] || (isset($secretariat) && $secretariat) || isset($items[0]['auth']['edit']) && $items[0]['auth']['edit']) { ?>
        <th class="actions" colspan='2'><?php __('Actions');?></th>
        <?php } ?>
    </tr>

    <?php if (!count($items)):?>
    <tr>
        <td colspan="6">No record found</td>
    </tr>
    <?php endif;?>

    <?php
    $i = 0;
    foreach ($items as $item):
        $class = null;
        if ($i++ % 2 == 0) {
            $class = ' class="altrow"';
        }
    ?>
        <tr<?php echo $class;?>>
            
            <td><?php echo $i.'.'?></td>
            <td>
                <?php 
                if($item['auth']['View']){
                    echo $html->link($item['Item']['name'],array('controller'=>'items','action'=>'view','id'=>$item['Item']['id'],'committee'=>$dcommittee['Committee']['short_name']));
                }else{
                    echo $item['Item']['name'];
                } 
                ?>
            </td>
            <td>
                <?php echo $item['Item']['short_name']; ?>
            </td>
            <td>
                <?php if($item['Item']['startdate'] == '0000-00-00'){echo"-";}else{echo date(Configure::read('date_format'),strtotime($item['Item']['startdate']));} ?>
            </td>
            <td>
                <?php if($item['Item']['deadline'] == '0000-00-00'){echo"-";}else{echo date(Configure::read('date_format'),strtotime($item['Item']['deadline']));} ?>
            </td>
    <?php 
        echo $this->element('crud',array('crudid'=>$item['Item']['id'],'permission'=>$item['auth']));
    ?>
        </tr>
    <?php endforeach; ?>
    </table>
</div>
<div class="paging">
    <?php echo $paginator->prev('<< '.__('previous', true), array('url'=>array('committee'=>$dcommittee['Committee']['short_name'])), null, array('class'=>'disabled'));?>
 |     <?php echo $paginator->numbers(array('url'=>array('committee'=>$dcommittee['Committee']['short_name'])));?>
    <?php echo $paginator->next(__('next', true).' >>', array('url'=>array('committee'=>$dcommittee['Committee']['short_name'])), null, array('class'=>'disabled'));?>
</div>

